package com.apinji.common.domain.mapper;

import com.apinji.common.data.PayStatusEnum;
import com.apinji.common.domain.TransactionRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by 轩辕夏夏 on 2017/7/5.
 */
@Mapper
public interface TransactionRecordMapper {


    @Insert("Insert into apin_transaction_record(id, useruuid, createtime, paystatus, frontrspstatus, cardtype, cardno, " +
            "orderid, ordername, orderdesc, fronturl, consumetype, consumetypename, outorderid, paychannel, txntype, txnsubtype, " +
            "biztype, channeltype, merid, txntime, txnamt, currencycode, token, tokenpaydata, smscode, queryid, traceno, tracetime, " +
            "settledate, settlecurrencycode, settleamt, respmsg, memo) " +

            "values(#{id}, #{userUUID}, #{createTime}, #{payStatus}, #{frontRspStatus}, #{cardType}, #{cardNo}, " +
            "#{orderId}, #{orderName}, #{orderDesc}, #{frontUrl}, #{consumeType}, #{consumeTypeName}, #{outOrderId}, #{payChannel}, #{txnType}, #{txnSubType}, " +
            "#{bizType}, #{channelType}, #{merId}, #{txnTime}, #{txnAmt}, #{currencyCode}, #{token}, #{tokenPayData}, #{smsCode}, #{queryId}, #{traceNo}, #{traceTime}, " +
            "#{settleDate}, #{settleCurrencyCode}, #{settleAmt}, #{respMsg}, #{memo})")
    void addTransactionRecord(TransactionRecord transactionRecord);

    @Update("update apin_transaction_record set paystatus = #{payStatus}, memo = #{memo} where id = #{id}")
    void updatePayStatus(@Param("id")String id, @Param("payStatus")int payStatus, @Param("memo")String memo);

    @Update("update apin_transaction_record set frontrspstatus = #{frontRspStatus} where id = #{id}")
    void updateFrontRspStatus(@Param("id")String id, @Param("frontRspStatus")String frontRspStatus);

    @Update("update apin_transaction_record set queryid = #{queryId}, traceno = #{traceNo}, tracetime = #{traceTime}, settledate = #{settleDate}, settlecurrencycode = #{settleCurrencyCode}, settleamt = #{settleAmt}, respmsg = #{respMsg} where id = #{id}")
    void updateCallBackInfo(@Param("id")String id, @Param("queryId")String queryId, @Param("traceNo")String traceNo, @Param("traceTime")String traceTime, @Param("settleDate")String settleDate,
                            @Param("settleCurrencyCode")String settleCurrencyCode, @Param("settleAmt")String settleAmt, @Param("respMsg")String respMsg);

    @Select("select * from apin_transaction_record where id = #{id}")
    TransactionRecord getOneById(@Param("id")String id);


    /**
     * 根据outOrderId查询支付成功的交易记录
     * @param userUUID  用户UUID
     * @param outOrderId  业务系统定义的订单ID
     * @return
     */
    //PAYMENT_TYPE
    @Select("select * from apin_transaction_record where outorderid = #{outOrderId} and useruuid = #{userUUID} and paystatus = #{payStatus} and consumetype = #{consumeType}")
    List<TransactionRecord> listRecords(@Param("outOrderId")String outOrderId, @Param("userUUID")String userUUID, @Param("payStatus")int payStatus, @Param("consumeType")int consumeType);

    @Select("select * from apin_transaction_record where id = #{id} and useruuid = #{userUUID}")
    TransactionRecord getOneItemByUser(@Param("id")String id, @Param("userUUID")String userUUID);


}
